﻿using System.Drawing.Drawing2D;
using DFGK.IService.BBS;
using DFGK_WMS.Common;
using DFGK_WMS.Model.BBS;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using NetTaste;

namespace DFGK_WMS.WebAPI.Controllers.Platform
{
    /// <summary>
    /// 资讯类别管理
    /// </summary>
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class InfomationTypeController : BaseController
    {
        private readonly IInfomationTypeService _infomationTypeService;

        public InfomationTypeController(IInfomationTypeService infomationTypeService, IWebHostEnvironment webEnvironment) : base(webEnvironment)
        {
            _infomationTypeService = infomationTypeService;
        }

        /// <summary>
        /// 分页查询
        /// </summary>
        /// <param name="name"></param>
        /// <param name="pageIndex"></param>
        /// <param name="pageSize"></param>
        /// <returns></returns>
        [HttpGet]
        public IActionResult GetPageData(string? name, int pageIndex = 1, int pageSize = 50)
        {
            int totalCount;
            var pageData = _infomationTypeService.GetInfoTypePageData(name, out totalCount, pageIndex, pageSize);
            return Ok(BaseResult.Result(pageData, "查询成功！", "200", totalCount));
        }

        /// <summary>
        /// 新增/修改资讯管理
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        [HttpPost]
        public IActionResult SubmitInfoType(InfomationType model)
        {

            if (model.Id > 0)
            {
                model.ModifyUserId = base.BaseGetNowUserId();
                model.ModifyUserName = base.BaseGetNowUserName();
            }
            else
            {
                model.CreateUserId = base.BaseGetNowUserId();
                model.CreateUserName = base.BaseGetNowUserName();
            }
            bool result = _infomationTypeService.SubmitInfoTypeData(model, out string message);
            if (result)
            {
                return Ok(BaseResult.Result(true, "添加成功！", "200"));
            }
            return Ok(BaseResult.Result(false, "添加失败！" + message, "500"));
        }

        /// <summary>
        /// ID查询
        /// </summary>
        /// <param name="infoTypeId"></param>
        /// <returns></returns>
        [HttpGet]
        public IActionResult GetInfoType(long infoTypeId)
        {
            var obj = _infomationTypeService.GetInfoType(infoTypeId);
            if (obj != null)
            {
                return Ok(BaseResult.Result(obj, "查询成功！", "200", 0));
            }
            return Ok(BaseResult.Result(null, "查询失败！", "500", 0));
        }

        /// <summary>
        /// 删除资讯类别
        /// </summary>
        /// <param name="infoTypeId">资讯类别Id</param>
        /// <returns></returns>
        [HttpDelete]
        public IActionResult DelInfoType(long infoTypeId)
        {
            bool result = _infomationTypeService.DelInfoType(infoTypeId);
            if (result)
            {
                return Ok(BaseResult.Result(true, "删除成功！", "200"));
            }
            return Ok(BaseResult.Result(false, "删除失败！", "500"));
        }
    }
}
